package com.baoyanghui.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import com.baoyanghui.common.InterfaceAccess;

/**
 * Servlet implementation class SearchPlaces
 */
public class SearchPlaces extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchPlaces() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject result;
		Map<String, String> params = new HashMap<String, String>();
		
		try {
			request.setCharacterEncoding("UTF-8");
			params.put("place_type", request.getParameter("place_type"));
			params.put("keyword", request.getParameter("keyword"));
			params.put("location", request.getParameter("location"));
			params.put("page", request.getParameter("page"));
			params.put("page_size", request.getParameter("page_size"));
			
			result = InterfaceAccess.callInterface("/search_places", params);
			
			response.setCharacterEncoding("UTF-8");
			response.getWriter().write(result.toString());	
			response.getWriter().flush();
		} catch (IOException e) {
		}
	}

}
